package com.alpha.eceasy.mall.controller;

import com.alpha.eceasy.mall.api.entity.MallCommodityDetail;
import com.alpha.eceasy.core.R;
import com.alpha.eceasy.mall.service.MallCommodityDetailService;
import com.alpha.eceasy.mall.service.impl.MallCommodityDetailServiceImpl;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.v3.oas.annotations.Hidden;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

/**
 * 商品详情表
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/commodity-detail")
@Hidden
@Tag(description  = "commodity-detail", name = "商品详情表")
public class MallCommodityDetailController {
	private final MallCommodityDetailServiceImpl mallCommodityDetailService;

	/**
	 * 分页查询
	 *
	 * @param page                分页对象
	 * @param mallCommodityDetail 商品详情
	 * @return 分页结果
	 */
	@Operation(description = "分页查询", summary = "分页查询")
	@GetMapping("")
	public R<IPage<MallCommodityDetail>> getMallCommodityDetailPage(Page<MallCommodityDetail> page, MallCommodityDetail mallCommodityDetail) {
		return R.ok(mallCommodityDetailService.page(page, Wrappers.query(mallCommodityDetail).eq("deleted", false)));
	}

	/**
	 * 通过id查询商品详情
	 *
	 * @param id id
	 * @return R 返回结果 商品详情
	 */
	@Operation(description = "通过id查询", summary = "通过id查询")
	@GetMapping("/{id}")
	public R<MallCommodityDetail> getById(@PathVariable("id") Long id) {
		return R.ok(mallCommodityDetailService.getById(id));
	}

	/**
	 * 通过条件查询商品详情
	 *
	 * @param mallCommodityDetail 查询条件
	 * @return R 返回结果 商品详情
	 */
	@Operation(description = "通过条件查询商品详情", summary = "通过条件查询商品详情")
	@GetMapping("/search")
	public R<MallCommodityDetail> getByMallCommodityDetail(MallCommodityDetail mallCommodityDetail) {
		return R.ok(mallCommodityDetailService.getOne(Wrappers.lambdaQuery(mallCommodityDetail)));
	}

	/**
	 * 新增商品详情
	 *
	 * @param mallCommodityDetail 商品详情
	 * @return R 返回结果 是否成功
	 */
	@Operation(description = "新增商品详情", summary = "新增商品详情")
	//@SysLog("新增商品详情")
	@PostMapping
	public R<Boolean> save(@RequestBody MallCommodityDetail mallCommodityDetail) {
		return R.ok(mallCommodityDetailService.save(mallCommodityDetail));
	}

	/**
	 * 修改商品详情
	 *
	 * @param mallCommodityDetail 商品详情
	 * @return R 返回结果 是否成功
	 */
	@Operation(description = "修改商品详情", summary = "修改商品详情")
	//@SysLog("修改商品详情")
	@PutMapping
	public R<Boolean> updateById(@RequestBody MallCommodityDetail mallCommodityDetail) {
		return R.ok(mallCommodityDetailService.updateById(mallCommodityDetail));
	}

}
